import 'package:get/get.dart';
import 'package:kkhousekeep/models/order_list_entity.dart';
import 'package:kkhousekeep/models/property_order_detail_entity.dart';

import '../../../../net/home_order_connect.dart';
import '../../../public/take_picture_screen.dart';

class RepairsDetailController extends GetxController {
  late OrderListObj _orderEntity;
  var area = "".obs;
  var address = "".obs;
  var reporter = "".obs;
  var phone = "".obs;
  var urgency = "".obs;
  var fatalType = "".obs;
  var fatalDesc = "".obs;
  var descImg = <String>[].obs;
  var records = <PropertyOrderDetailObjRecord>[].obs;

  late HomeOrderConnect _homeOrderConnect;

  @override
  void onInit() {
    _homeOrderConnect = Get.find<HomeOrderConnect>();
    _orderEntity = Get.arguments;
    super.onInit();
    _loadNetworkData();
  }

  Future<void> _loadNetworkData() async {
    PropertyOrderDetailEntity orderDetailEntity =
        await _homeOrderConnect.getOrderDetail(orderId: _orderEntity.id);
    PropertyOrderDetailObj orderDetailObj = orderDetailEntity.obj;
    address.value = orderDetailObj.address;
    reporter.value = orderDetailObj.reporter;
    phone.value = orderDetailObj.phone;
    switch (orderDetailObj.area) {
      case 1:
        area.value = "户内";
        break;
      case 2:
        urgency.value = "户外";
        break;
    }
    switch (orderDetailObj.urgency) {
      case 1:
        urgency.value = "一般";
        break;
      case 2:
        urgency.value = "紧急";
        break;
      case 3:
        urgency.value = "非常急";
        break;
    }
    fatalType.value = orderDetailObj.fatalType;
    address.value = orderDetailObj.address;
    fatalDesc.value = orderDetailObj.fatalDesc;
    descImg.value = orderDetailObj.pics;
    records.value = orderDetailObj.record;
  }

  void clickImageItem(String path) {
    Get.to(
      DisplayPictureScreen(
        imagePath: path,
        isShowRetake: false,
      ),
    );
  }
}
